package com.coding.base.pojo;


import com.wordnik.swagger.annotations.ApiModelProperty;

import java.io.Serializable;

public class PageQueryModel implements Serializable {
    @ApiModelProperty("页号，默认为1")
    private Integer page;
    @ApiModelProperty("页内大小，默认为10")
    private Integer size;
    @ApiModelProperty(value = "起始位置，自动计算", hidden = true)
    private Integer offset;

    public PageQueryModel() {
        this.page = 1;
        this.size = 10;
        this.offset = this.page * this.size;
    }

    public PageQueryModel(Integer page, Integer size) {
        this.page = page;
        if (this.page <= 0)
            this.page = 1;
        this.size = size;
        this.offset = this.page * this.size;
    }

    public Integer getPage() {
        return page;
    }

    public void setPage(Integer page) {
        this.page = page;
    }

    public Integer getSize() {
        return size;
    }

    public void setSize(Integer size) {
        this.size = size;
    }

    public Integer getOffset() {
        int page = this.page - 1;
        int size = this.size;
        if (page < 0)
            page = 0;
        return page * size;
    }

}
